#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
struct ListNode {
   int val;
   struct ListNode* next;
   
};
bool isPalindrome(struct ListNode* head) {
    if (head == NULL)
    {
        return false;
    }
    if (head->next == NULL)
    {
        return true;
    }
    int size = 0;
    struct ListNode* src = head;
    while (src)
    {
        src = src->next;
        size++;
    }
    src = head;
    if (size % 2 == 0)
    {
        int i = size / 2 - 1;
        while (i > 0)
        {
            src = src->next;
            i--;
        }
        struct ListNode* Mid = src->next, * Next = Mid->next, * Pre = NULL;
        src->next = NULL;
        while (Mid)
        {
            Mid->next = Pre;
            Pre = Mid;
            Mid = Next;
            if (Next != NULL)
            {
                Next = Next->next;
            }
        }
        src = head;
        while (Pre && src)
        {
            if (Pre->val == src->val)
            {
                Pre = Pre->next;
                src = src->next;
            }
            else {
                return false;
            }
        }
        return true;
    }
    else {
        int i = size / 2;
        while (i > 0)
        {
            src = src->next; i--;
        }
        struct ListNode* Mid = src->next, * Next = Mid->next, * Pre = src;
        while (Mid)
        {
            Mid->next = Pre;
            Pre = Mid;
            Mid = Next;
            if (Next != NULL)
            {
                Next = Next->next;
            }
        }
        src = head;
        while (Pre != src)
        {
            if (Pre->val == src->val)
            {
                Pre = Pre->next;
                src = src->next;
            }
            else {
                return false;
            }
        }
        return true;
    }
    return true;
}